import matplotlib.pyplot as plt
import numpy as np

# 中文显示
plt.rcParams['font.sans-serif'] = ['Microsoft YaHei']
plt.rcParams['axes.unicode_minus'] = False

def demonstrate_slope():
    """演示直线斜率的几何意义"""
    x0, y0 = 1, 2  # 起点
    x1, y1 = 4, 5  # 终点
    
    # 计算斜率
    slope = (y1 - y0) / (x1 - x0)
    
    plt.figure(figsize=(8, 6))
    plt.plot([x0, x1], [y0, y1], 'b-', linewidth=2, label=f'直线L, 斜率k={slope}')
    plt.scatter([x0, x1], [y0, y1], color='red', s=100)
    
    # 标注坐标
    plt.annotate(f'({x0}, {y0})', (x0, y0), xytext=(x0-0.1, y0+0.1))
    plt.annotate(f'({x1}, {y1})', (x1, y1), xytext=(x1+0.2, y1))
    
    plt.title('直线斜率的几何意义')
    plt.xlabel('x'); plt.ylabel('y')
    plt.grid(True, alpha=0.3)
    plt.legend()
    plt.axis('equal')
    plt.show()

demonstrate_slope()